# Find OgreNewt (Newton physic library bindings for OGRE)
#
# This module defines
# OGRENEWT_FOUND       - OgreNewt was found
# OGRENEWT_INCLUDE_DIR - Directory containing OgreNewt header files
# OGRENEWT_LIBRARY     - Library name of OgreNewt library
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

# On a new cmake run, we do not need to be verbose
IF(OGRENEWT_INCLUDE_DIR AND OGRENEWT_LIBRARY)
	SET(OGRENEWT_FOUND_QUIETLY TRUE)
ENDIF(OGRENEWT_INCLUDE_DIR AND OGRENEWT_LIBRARY)

IF(WIN32)

ELSE(WIN32)
	IF(PKG_CONFIG_FOUND)
		IF(OgreNewt_FIND_VERSION)
			IF(OgreNewt_FIND_VERSION_EXACT)
				PKG_SEARCH_MODULE(OGRENEWT REQUIRED OgreNewt=${OgreNewt_FIND_VERSION})
			ELSE(OgreNewt_FIND_VERSION_EXACT)
				PKG_SEARCH_MODULE(OGRENEWT REQUIRED OgreNewt>=${OgreNewt_FIND_VERSION})
			ENDIF(OgreNewt_FIND_VERSION_EXACT)
		ELSE(OgreNewt_FIND_VERSION)
			PKG_SEARCH_MODULE(OGRENEWT REQUIRED OgreNewt)
		ENDIF(OgreNewt_FIND_VERSION)
		SET(OGRENEWT_INCLUDE_DIR ${OGRENEWT_INCLUDE_DIRS})
		SET(OGRENEWT_LIBRARY ${OGRENEWT_LIBRARIES})
	ENDIF(PKG_CONFIG_FOUND)
	IF(NOT OGRENEWT_FOUND)
		SET(OGRENEWT_INCLUDE_SEARCH_DIRS
		    /usr/include
		    /usr/local/include
		    /opt/include
		    /opt/OgreNewt/include)
		SET(OGRENEWT_LIBRARY_SEARCH_DIRS
		    /usr/lib
		    /usr/lib64
		    /usr/local/lib
		    /usr/local/lib64
		    /opt/OgreNewt/lib
		    /opt/OgreNewt/lib64)
		SET(OGRENEWT_INC_DIR_SUFFIXES PATH_SUFFIXES OgreNewt)
		FIND_PATH(OGRENEWT_INCLUDE_DIR OgreNewt.h
		          PATHS ${OGRENEWT_INCLUDE_SEARCH_DIRS}
		          PATH_SUFFIXES ${OGRENEWT_INC_DIR_SUFFIXES})
		FIND_LIBRARY(OGRENEWT_LIBRARY OgreNewt
		             PATHS ${OGRENEWT_LIBRARY_SEARCH_DIRS}
		             PATH_SUFFIXES ${OGRENEWT_LIB_DIR_SUFFIXES}})
	ENDIF(NOT OGRENEWT_FOUND)
ENDIF(WIN32)

SET(OGRENEWT_INCLUDE_DIR ${OGRENEWT_INCLUDE_DIR} CACHE STRING "Directory containing OgreNewt header files")
SET(OGRENEWT_LIBRARY ${OGRENEWT_LIBRARY} CACHE STRING "Library name of OgreNewt library")

IF(OGRENEWT_INCLUDE_DIR AND OGRENEWT_LIBRARY)
	SET(OGRENEWT_FOUND TRUE)
ENDIF(OGRENEWT_INCLUDE_DIR AND OGRENEWT_LIBRARY)

IF(OGRENEWT_FOUND)
	IF(NOT OGRENEWT_FIND_QUIETLY)
		MESSAGE(STATUS "  libraries: ${OGRENEWT_LIBRARY} from ${OGRENEWT_LIBRARY_DIRS}")
		MESSAGE(STATUS "  includes: ${OGRENEWT_INCLUDE_DIR}")
	ENDIF(NOT OGRENEWT_FIND_QUIETLY)
ELSE(OGRENEWT_FOUND)
	IF(OgreNewt_FIND_REQUIRED)
		IF(NOT OGRENEWT_LIBRARY)
			MESSAGE(SEND_ERROR, "OgreNewt library could not be found.")
		ENDIF(NOT OGRENEWT_LIBRARY)
		IF(NOT OGRENEWT_INCLUDE_DIR)
			MESSAGE(SEND_ERROR "OgreNewt include files could not be found.")
		ENDIF(NOT OGRENEWT_INCLUDE_DIR)
	ENDIF(OgreNewt_FIND_REQUIRED)
ENDIF(OGRENEWT_FOUND)